import data from "./data";
import { useBreadCrumbStore } from "@/piniastore";


function getBreadCrumb(path: string) {
  let arr = [
    {
      label: data[0].title,
      to: data[0].to,
    }
  ];

  for (let i = 0; i < data.length; i++) {
    if (data[i].to) {
      if (data[i].to === path) {
        arr.push({
          label: data[i].title,
          to: data[i].to,
        });
        return arr;
      }
    } else {
      for (let j = 0; j < data[i].children.length; j++) {
        if (data[i].children[j].to === path) {
          arr.push({
            label: data[i].title,
          });
          arr.push({
            label: data[i].children[j].title,
            to: data[i].children[j].to,
          });
          return arr;
        }
      }
    }
  }
}

export const dobreadcurmb = (path: string) => {
  const store = useBreadCrumbStore()
  let arr = getBreadCrumb(path);
  store.changeBreadcrumbs(arr)

};
